import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/widgets/animate/animate_view.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_small_button.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';
import 'package:kq_flutter_widgets/widgets/update/update_view.dart';

class AnimateViewDemo extends StatefulWidget {
  const AnimateViewDemo({super.key});

  @override
  State<StatefulWidget> createState() => AnimateDemoState();
}

class AnimateDemoState extends State<AnimateViewDemo> {
  TranslationAnimateType type = TranslationAnimateType.translateIn;
  int angle = 0;
  UpdateViewState? updateViewState;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: 'KqAnimateView控件动画演示',
        back: () {
          Get.back();
        },
      ),
      body: Column(
        children: [
          const SizedBox(height: 20),
          Row(
            children: [
              const SizedBox(width: 20),
              KqSmallButton(
                title: '左往右平移',
                onTap: (disabled) {
                  angle = TranslationAnimateDirection.leftToRight.angle;
                  updateViewState?.update();
                },
              ),
              const SizedBox(width: 20),
              KqSmallButton(
                title: '右往左平移',
                onTap: (disabled) {
                  angle = TranslationAnimateDirection.rightToLeft.angle;
                  updateViewState?.update();
                },
              ),
              const SizedBox(width: 20),
              KqSmallButton(
                title: '上往下平移',
                onTap: (disabled) {
                  angle = TranslationAnimateDirection.topToBottom.angle;
                  updateViewState?.update();
                },
              ),
              const SizedBox(width: 20),
              KqSmallButton(
                title: '下往上平移',
                onTap: (disabled) {
                  angle = TranslationAnimateDirection.bottomToTop.angle;
                  updateViewState?.update();
                },
              ),
            ],
          ),
          const SizedBox(height: 20),
          Row(
            children: [
              const SizedBox(width: 20),
              KqSmallButton(
                title: '平移入场',
                onTap: (disabled) {
                  type = TranslationAnimateType.translateIn;
                  updateViewState?.update();
                },
              ),
              const SizedBox(width: 20),
              KqSmallButton(
                title: '平移出场',
                onTap: (disabled) {
                  type = TranslationAnimateType.translateOut;
                  updateViewState?.update();
                },
              ),
            ],
          ),
          const SizedBox(height: 20),
          Expanded(
            child: UpdateView(
              build: (UpdateViewState state) {
                updateViewState = state;
                return AnimateView(
                  isNeedFlashEveryTime: true,
                  animate: TranslationAnimate(angle: angle, type: type),
                  child: Container(
                    color: Colors.redAccent,
                  ),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
